package com.hhf.lambda;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Author hhf
 * @Date 2024/6/10
 * @Description lambda的实战 1.排序 2.启动线程
 */
public class Lambda2 {

    public static void main(String[] args) {
        List<String> fruitList = new ArrayList<>();
        fruitList.add("Apple");
        fruitList.add("Banana");
        fruitList.add("Orange");

        //1.对列表排序原先的写法
        Collections.sort(fruitList, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });

        //2.lambda写法
        Collections.sort(fruitList,((o1, o2) -> {
            return o1.compareTo(o2);
            //return o2.compareTo(o1);
        }));

        //3.类::方法  引用类中的实例方法
        Collections.sort(fruitList,String::compareTo);//此方法只能使用默认的排序规则

        //---------------------------------------------------------------------------------------

        //原先启动线程
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("hello world");
            }
        });
        //lambda表达式
        new Thread(()->{
            System.out.println("hello world");
        });

    }
}
